# Definition for singly-linked list.
class ListNode(object):
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution(object):
    def middleNode(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        if head is None:
            return None
        # if head.next == None:
        #     return head
        # else:
        #     cur = head
        #     count=0
        #     while cur :
        #         cur = cur.next
        #         count+=1
        #
        #     count2 = int(count/2)
        #     m = head
        #     if count2 % 2 ==1:
        #         for i in range(count2):
        #             m = m.next
        #         return m
        #     else:
        #         for i in range(count2 - 1):
        #             m=  m.next
        #         return m.next

        fast = low = head

        while fast and fast.next:
            low = low.next
            fast = fast.next.next
        return low


